package com.ktwlsoft.archivemanage.controller.sms;

import com.ktwlsoft.archivemanage.domain.business.businessService.SmsBusinessService;
import com.ktwlsoft.archivemanage.domain.dao.entity.sms.SendSms;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.ResultType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 短信控制器
 *
 * @author zhuhe on 2019/10/28 10:17
 * @version 1.0
 */
@Api(value = "短信", description = "短信")
@RestController
@RequestMapping("sms")
public class SmsController {

    @Autowired
    private SmsBusinessService service;

    /**
     * 短信发送
     * @param model 请求参数
     * @return ResponseEntity<Object>
     */
    @ApiOperation(value = "短信发送", httpMethod = "POST", produces = "application/json", response = SendSms.class)
    @ResponseBody
    @PostMapping("sendSms")
    public ResponseEntity<?> sendSms(@RequestBody @Valid SendSms model, BindingResult result){
        if(result.hasErrors()){
            return ResponseEntity.ok(Result.body(model, ResultType.CHECK_ERROR).withMessage(result.getFieldError().getDefaultMessage()));
        }
        return ResponseEntity.ok(service.sendSms(model));
    }

    @ApiOperation(value = "根据类型发送短信")
    @ResponseBody
    @GetMapping("sendBusinessSms")
    public ResponseEntity<?> sendBusinessSms(@ApiParam(name = "id", value = "业务数据id") @RequestParam(defaultValue = "") Long id,
                                             @ApiParam(name = "phone", value = "手机号码") @RequestParam(defaultValue = "") String phone,
                                             @ApiParam(name = "type", value = "类型:1.注册申请提交,2.指导申请已提交提醒,3.指导申请未通过验证," +
                                                       "4.指导申请已通过验证,5.业务指导待确认,6.业务指导已确认,7.新增指导整改,8.指导整改提交提醒," +
                                                       "9.指导整改未通过验证,10.业务检查待确认,11.业务检查已确认，12.新增检查整改,13.检查整改已提交," +
                                                       "14.检查整改未通过验证,15.年度报送已提交,16.年度报送报送未通过验证") @RequestParam(defaultValue = "") Integer type) {
        return ResponseEntity.ok(service.sendBusinessSms(id,phone, type));
    }
}